<#include "/common/layout.html">
<@body>
<div class="content">
	<form role="form" class="form-horizontal" method="post" action="${request.contextPath}/mall/category/doEdit" id="editCategoryForm">
		<div class="box-body">
			<input type="hidden" value="${(category.categoryId)}" name="categoryId" />
			<div class="form-group">
				<label class="col-sm-2 control-label">上级类目</label>
				<div class="col-sm-10">
					<select id="parentId" name="parentId" class="form-control select2" style="width: 100%;" data-placeholder="--请选择类目--">
						<option></option>
						<option value="0" ${(category.parentId?? && category.parentId == 0)?string('selected="selected"','')}>顶级类目</option>
						<#list categoryList as categorys>
						<option value="${categorys.categoryId}" ${(category.parentId?? && categorys.categoryId == category.parentId)?string('selected="selected"','')} >${categorys.name}</option>
						</#list>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类目名称</label>
				<div class="col-sm-10">
					<input type="text" id="name" name="name" class="form-control" placeholder="请输入类目名称" value="${(category.name)}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类目描述</label>
				<div class="col-sm-10">
					<input type="text" id="descripte" name="descripte" class="form-control" placeholder="请输入类目描述" value="${(category.descripte)}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类目状态</label>
				<div class="col-sm-10">
					<label class="radio-box"><input type="radio" name="status" value="1" ${(category.status?? && category.status== 1)?string('checked','')} class="form-control minimal"> 正常</label>
					<label class="radio-box"><input type="radio" name="status" value="0" ${(category.status?? && category.status== 0)?string('checked','')} class="form-control minimal"> 停用</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类目图片</label>
				<div class="col-sm-10">
					<input type="hidden" id="picUrl" name="picUrl" value="${category.picUrl}">
					<div class="file-loading">
			            <input id="uploadImg" name="file" type="file" multiple>
			        </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类目排序</label>
				<div class="col-sm-10">
					<input type="text" id="sortOrder" name="sortOrder" class="form-control" placeholder="请输入类目排序" value="${(category.sortOrder)}" required>
				</div>
			</div>
		</div>
	</form>
</div>
</@body>
<script type="text/javascript">
	
	//单图上传
	$("#uploadImg").fileinput({
	    uploadUrl: '${request.contextPath}/system/sysfile/upload',
	    maxFileCount: 1,
	    autoReplace: true,
	    initialPreviewAsData: true,
	    initialPreview: ['${(category.picUrl)!}'],
	    layoutTemplates:{
            actionUpload:'',//去除上传预览缩略图中的上传图片
            actionDownload:'' ,//去除上传预览缩略图中的下载图标
            actionDelete:'', //去除上传预览的缩略图中的删除图标
        },
	}).on('fileuploaded', function (event, data, previewId, index) {
		var rsp = data.response;
		console.log("return fileUrl：" + rsp.fileUrl);
		console.log("reutrn fileName：" + rsp.fileName);
	    $('#picUrl').val(rsp.fileUrl);
	}).on('filecleared', function(event) {
		$('#picUrl').val('');
	})
	
	function submitHandler() {
		if ($("#editCategoryForm").validate().form()) {
			var categoryImg = $('#picUrl').val();
			if(categoryImg == null || categoryImg == undefined || categoryImg == '') {
				layer.msg("请上传类目图片", {icon : 2});
				return false;
			}
			var formData = $("#editCategoryForm").serialize();
			var index = layer.load(3); // 换了种风格
			$.ajax({
				url : $("#editCategoryForm").attr('action'),
				type : 'POST',
				dataType : "json",
				data : formData,
				beforeSend : function() {
					$.modal.loading("正在处理中，请稍后...");
					$.modal.disable();
				},
				success : function(data) {
					layer.close(index);
					if (data.code == 200) {
						if (data.msg) {
							parent.layer.msg(data.msg, {
								icon : 1
							});
						} else {
							parent.layer.msg('提交成功', {
								icon : 1
							});
						}
						parent.layer.closeAll('iframe'); // 关闭当前frame
						window.parent.dataTable.draw(false);
					} else {
						layer.msg(data.msg, {
							icon : 2
						});
						$.modal.closeLoading();
						$.modal.enable();
					}
				}
			});
		}
	}
</script>